package operation;

import book.BookList;

import java.util.Scanner;

public class find implements IOperation{

    public int find_name(BookList Booklist,String bookname) {
        for (int i = 0;i < Booklist.getCount();i++) {
            if(bookname.equals(Booklist.getBooklist()[i].getBookname())) {
                return i;
            }
        }
        return -1;
    }


    @Override
    public void work(BookList Booklist) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入你需要寻找书籍的书名：");
        String bookname = scanner.next();
        int number = find_name(Booklist,bookname);
        if(number<0) {
            System.out.println("该书籍不存在,查询失败！！！");
        } else {
            System.out.println("查询成功！！！");
            System.out.println(Booklist.getBooklist()[number]);
        }
    }
}